<script setup>
import {formatTime} from "@/utils/format.js";
import {defineProps} from "vue";
import {useRouter} from "vue-router";

const props = defineProps({
  game: Object
})

// 游戏详情页
const router = useRouter()
const gameDetail = () => {
  router.push(`/store/detail/${props.game.id}`)
}
</script>

<template>
  <div class="game-container" @click="gameDetail">
    <div class="card">
      <img v-img-lazy="game.higherPicture">
      <div class="game-base-info">
        <div class="name">{{ game.chineseName }}</div>
        <div class="issue-date">
          <span>发行日期:</span>
          <span>{{formatTime(game.issueDate)}}</span>
        </div>
        <div class="price">
          <template v-if="game.gamePrice.currentPrice === '0.00'">
            免费开玩
          </template>
          <template v-else>
            <template v-if="game.gamePrice.discount === 0">
              ￥{{ game.gamePrice.originPrice }}
            </template>
            <template v-else>
              <div class="discount">
                <div class="discount-percent">-{{game.gamePrice.discount}}%</div>
                <div class="discount-price">
                  <span class="discount-origin-price">￥{{ game.gamePrice.originPrice }}</span>
                  <span class="discount-current-price">￥{{ game.gamePrice.currentPrice }}</span>
                </div>
              </div>
            </template>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.game-container {
  cursor: pointer;
  .card {
    width: 300px;
    height: 380px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 8px rgba(0, 0, 0, 1);
    img {
      width: 100%;
      object-position: top;
      object-fit: cover;
    }
    .game-base-info {
      padding: 6px;
      width: 100%;
      height: 150px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      position: absolute;
      left: 0;
      bottom: -150px;
      background-color: rgba($textColor, 0.5);
      backdrop-filter: blur(2px);
      color: #cccccc;
      text-shadow: 2px 2px 4px rgba(0, 0, 0, 1);
      transition: all 0.5s;
      .name {
        font-size: 22px;
      }
      .issue-date {
        span {
          display: block;
        }
      }
      .price {
        margin-bottom: 10px;
        .discount {
          display: flex;
          font-size: 14px;
          .discount-percent {
            padding: 0 4px;
            background-color: $discountBackgroundColor;
            color: $discountTextColor;
            text-shadow: 1px 1px 4px rgba(0, 0, 0, 1);
          }
          .discount-price {
            text-align: center;
            background-color: #525252;
            .discount-origin-price {
              margin: 0 4px;
              position: relative;
              color: #738895;
              &:before {
                content: '';
                left: 0;
                right: 0;
                position: absolute;
                top: 43%;
                border-bottom: 1.5px solid #738895;
                transform: skewY(-8deg);
                box-shadow: 0 0 2px black;
              }
            }
            .discount-current-price {
              padding: 0 4px 0 0;
            }
          }
        }
      }
    }
    &:hover .game-base-info {
      bottom: 0;
    }
  }
}
</style>
